package com.xcity.game.item.drop;

import java.util.Random;

import com.xcity.db.entity.Player;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.item.drop.listener.DropListener;

/**
 * 概率掉落
 * @author yang.li
 *
 */
public abstract class AbstractDrop implements Drop {

	/** 掉落概率(万分比) */
	protected int probability;
	
	public AbstractDrop() {}
	
	public AbstractDrop(int probability) {
		this.probability = probability;
	}
	
	@Override
	public boolean drop(Random rnd, Player player, String cause, DropListener listener) {
		if (probability >= GameStaticConfig.defaultChanceBase
				|| rnd.nextInt(GameStaticConfig.defaultChanceBase) < probability) {
			processDrop(player, cause, listener);
			return true;
		}
		return false;
	}

	protected abstract void processDrop(Player player, String cause, DropListener listener);
	
}
